*************************************************************
*Figures 6c & 6d - Divisive Vote Timing Effect Predictions
*************************************************************

*****CYCLES*******

use "VoteTiming_MASTER.dta"

set more off 

set seed 1234

gen DaysCycle=DaysToElection*Cycle

gen DemPercYea=TotalDemYeas/TotalDemVotes
gen DemPercNay=TotalDemNays/TotalDemVotes
gen RepPercYea=TotalRepYeas/TotalRepVotes
gen RepPercNay=TotalRepNays/TotalRepVotes

gen HyperDivisive=0
replace HyperDivisive=1 if DemPercYea>=.9 & RepPercNay>=.9
replace HyperDivisive=1 if DemPercNay>=.9 & RepPercYea>=.9

logit HyperDivisive DaysToElection Cycle DaysCycle RegPass Susp MiscPro Amend ProPart, robust

drawnorm M1_b1-M1_b9, n(10000) means(e(b)) cov(e(V)) clear

forvalues i=1(1)735 {
scalar days=`i'
scalar days2=days^2
scalar days3=days^3
scalar Cycle1=8
scalar Cycle32=32
scalar daysCycle1=days*Cycle1
scalar daysCycle32=days*Cycle32
scalar RegPass1=.409396
scalar RegPass32=.0564103
scalar Susp1=.0939597
scalar Susp32=.0555556
scalar MiscPro1=.0469799
scalar MiscPro32=.7094017 
scalar Amend1=.114094 
scalar Amend32=.0632479 
scalar ProPart1=.261745
scalar ProPart32=.1068376
scalar MajTopic2_1=.033557 
scalar MajTopic2_32=.0216802
scalar MajTopic3_1=.0738255
scalar MajTopic3_32=.0135501 
scalar MajTopic4_1=0
scalar MajTopic4_32=.100271
scalar MajTopic5_1=.0268456
scalar MajTopic5_32=.0054201 
scalar MajTopic6_1=.0268456
scalar MajTopic6_32=0
scalar MajTopic7_1=.0268456
scalar MajTopic7_32=.1517615
scalar MajTopic8_1=.1543624
scalar MajTopic8_32=.0731707
scalar MajTopic9_1=0
scalar MajTopic9_32=.0216802
scalar MajTopic10_1=.0536913 
scalar MajTopic10_32=0
scalar MajTopic11_1=.0402685
scalar MajTopic11_32=.0406504
scalar MajTopic12_1=.033557
scalar MajTopic12_32=.0352304 
scalar MajTopic13_1=.2214765
scalar MajTopic13_32=.2195122
scalar MajTopic14_1=.0939597
scalar MajTopic14_32=.0677507
scalar MajTopic15_1=0
scalar MajTopic15_32=0
scalar MajTopic16_1=.0134228
scalar MajTopic16_32=.0596206
scalar MajTopic17_1=.0805369
scalar MajTopic17_32=.0108401
scalar MajTopic18_1=.0067114
scalar MajTopic18_32=.0542005 
scalar MajTopic19_1=.0469799
scalar MajTopic19_32=.0162602
scalar MajTopic20_1=.0201342
scalar MajTopic20_32=.0921409
scalar MajTopic21_1=.0469799
scalar MajTopic21_32=.0108401
scalar MajTopic22_1=0
scalar MajTopic22_32=.0054201
scalar constant=1
generate x_betahatA_`i'=M1_b1*days + M1_b2*Cycle1 + M1_b3*daysCycle1 + M1_b4*RegPass1 + M1_b5*Susp1 + M1_b6*MiscPro1 + M1_b7*Amend1 + M1_b8*ProPart1 + M1_b9*constant
generate predA_`i'=1/(1+exp(-(x_betahatA_`i')))
drop x_betahatA_`i'
}

forvalues i=1(1)735 {
scalar days=`i'
scalar days2=days^2
scalar days3=days^3
scalar Cycle1=8
scalar Cycle32=32
scalar daysCycle1=days*Cycle1
scalar daysCycle32=days*Cycle32
scalar RegPass1=.409396
scalar RegPass32=.0564103
scalar Susp1=.0939597
scalar Susp32=.0555556
scalar MiscPro1=.0469799
scalar MiscPro32=.7094017 
scalar Amend1=.114094 
scalar Amend32=.0632479 
scalar ProPart1=.261745
scalar ProPart32=.1068376
scalar MajTopic2_1=.033557 
scalar MajTopic2_32=.0216802
scalar MajTopic3_1=.0738255
scalar MajTopic3_32=.0135501 
scalar MajTopic4_1=0
scalar MajTopic4_32=.100271
scalar MajTopic5_1=.0268456
scalar MajTopic5_32=.0054201 
scalar MajTopic6_1=.0268456
scalar MajTopic6_32=0
scalar MajTopic7_1=.0268456
scalar MajTopic7_32=.1517615
scalar MajTopic8_1=.1543624
scalar MajTopic8_32=.0731707
scalar MajTopic9_1=0
scalar MajTopic9_32=.0216802
scalar MajTopic10_1=.0536913 
scalar MajTopic10_32=0
scalar MajTopic11_1=.0402685
scalar MajTopic11_32=.0406504
scalar MajTopic12_1=.033557
scalar MajTopic12_32=.0352304 
scalar MajTopic13_1=.2214765
scalar MajTopic13_32=.2195122
scalar MajTopic14_1=.0939597
scalar MajTopic14_32=.0677507
scalar MajTopic15_1=0
scalar MajTopic15_32=0
scalar MajTopic16_1=.0134228
scalar MajTopic16_32=.0596206
scalar MajTopic17_1=.0805369
scalar MajTopic17_32=.0108401
scalar MajTopic18_1=.0067114
scalar MajTopic18_32=.0542005 
scalar MajTopic19_1=.0469799
scalar MajTopic19_32=.0162602
scalar MajTopic20_1=.0201342
scalar MajTopic20_32=.0921409
scalar MajTopic21_1=.0469799
scalar MajTopic21_32=.0108401
scalar MajTopic22_1=0
scalar MajTopic22_32=.0054201
scalar constant=1
generate x_betahatB_`i'=M1_b1*days + M1_b2*Cycle32 + M1_b3*daysCycle32 + M1_b4*RegPass32 + M1_b5*Susp32 + M1_b6*MiscPro32 + M1_b7*Amend32 + M1_b8*ProPart32 + M1_b9*constant
generate predB_`i'=1/(1+exp(-(x_betahatB_`i')))
drop x_betahatB_`i'
}

foreach var of varlist predA_1-predA_735{
egen `var'a=clsort(`var')
}

foreach var of varlist predB_1-predB_735{
egen `var'b=clsort(`var')
}

save "Figure6c1_Values.dta"

drop M1_b1-predB_735
gen days=_n
*Keep the 8.25th and 91.75th percentiles
keep if days==825 | days==9175
xpose, clear
rename v1 LowBound
rename v2 UpBound
drop in 1471
gen days=_n
move days LowBound
gen Type="Early Cycle" if days<736
replace Type="Late Cycle" if days>735
replace days=days-735 if days>735

save "Figure6c1_Preds.dta"

*twoway (scatter LowBound days if Type=="Early Cycle") (scatter UpBound days if Type=="Early Cycle") (scatter LowBound days if Type=="Late Cycle") (scatter UpBound days if Type=="Late Cycle")
clear
*Reshape for figure
use "Figure6c1_Preds.dta"
sort days
gen shaper=1 if Type=="Early Cycle"
replace shaper=32 if Type=="Late Cycle"
drop Type
reshape wide LowBound UpBound, i(days) j(shaper)
save "Figure6c1_Preds_reshaped.dta"
clear


*****POST-104 INDICATOR*******

use "VoteTiming_MASTER.dta"

set more off 

set seed 1234

gen post1994elec=1 if Cycle>=21
replace post1994elec=0 if post1994elec==.

gen DaysPost=DaysToElection*post1994elec

gen DemPercYea=TotalDemYeas/TotalDemVotes
gen DemPercNay=TotalDemNays/TotalDemVotes
gen RepPercYea=TotalRepYeas/TotalRepVotes
gen RepPercNay=TotalRepNays/TotalRepVotes

gen HyperDivisive=0
replace HyperDivisive=1 if DemPercYea>=.9 & RepPercNay>=.9
replace HyperDivisive=1 if DemPercNay>=.9 & RepPercYea>=.9

logit HyperDivisive DaysToElection post1994elec DaysPost RegPass Susp MiscPro Amend ProPart, robust

drawnorm M1_b1-M1_b9, n(10000) means(e(b)) cov(e(V)) clear

forvalues i=1(1)735 {
scalar days=`i'
scalar days2=days^2
scalar days3=days^3
scalar Post104_1=1
scalar Post104_0=.25
scalar daysPost104_1=days*Post104_1
scalar daysPost104_0=days*Post104_0
scalar RegPass1=.1130397
scalar RegPass0=.2608965
scalar Susp1=.1359734
scalar Susp0=.0978276
scalar MiscPro1=.1297074
scalar MiscPro0=.1079335
scalar Amend1=.3178144
scalar Amend0=.3066135 
scalar ProPart1=.208597
scalar ProPart0=.174206 
scalar MajTopic2_1=.0514301
scalar MajTopic2_0=.056308 
scalar MajTopic3_1=.0343752
scalar MajTopic3_0=.0506703
scalar MajTopic4_1=.0503019
scalar MajTopic4_0=.0362324
scalar MajTopic5_1=.0149977
scalar MajTopic5_0=.0299759
scalar MajTopic6_1=.0189794
scalar MajTopic6_0=.025507
scalar MajTopic7_1=.0657642
scalar MajTopic7_0=.0372637
scalar MajTopic8_1=.1053819
scalar MajTopic8_0=.1100034 
scalar MajTopic9_1=.0224965 
scalar MajTopic9_0=.023582
scalar MajTopic10_1=.0169885
scalar MajTopic10_0=.0220007
scalar MajTopic11_1=.0640388
scalar MajTopic11_0=.0775524
scalar MajTopic12_1=.0297963
scalar MajTopic12_0=.0329323 
scalar MajTopic13_1=.2243015 
scalar MajTopic13_0=.2219319
scalar MajTopic14_1=.0644369
scalar MajTopic14_0=.0694397
scalar MajTopic15_1=.0027872
scalar MajTopic15_0=.0045376
scalar MajTopic16_1=.049572
scalar MajTopic16_0=.0275696
scalar MajTopic17_1=.0248192 
scalar MajTopic17_0=.0349948
scalar MajTopic18_1=.0212356
scalar MajTopic18_0=.0365074
scalar MajTopic19_1=.0352379
scalar MajTopic19_0=.0255758
scalar MajTopic20_1=.0462539
scalar MajTopic20_0=.0295634
scalar MajTopic21_1=.0447939
scalar MajTopic21_0=.039395
scalar MajTopic22_1=.0118787
scalar MajTopic22_0=.0084565
scalar constant=1
generate x_betahatA_`i'=M1_b1*days + M1_b2*Post104_0 + M1_b3*daysPost104_0 + M1_b4*RegPass0 + M1_b5*Susp0 + M1_b6*MiscPro0 + M1_b7*Amend0 + M1_b8*ProPart0 + M1_b9*constant
generate predA_`i'=1/(1+exp(-(x_betahatA_`i')))
drop x_betahatA_`i'
}

forvalues i=1(1)735 {
scalar days=`i'
scalar days2=days^2
scalar days3=days^3
scalar Post104_1=1
scalar Post104_0=.25
scalar daysPost104_1=days*Post104_1
scalar daysPost104_0=days*Post104_0
scalar RegPass1=.1130397
scalar RegPass0=.2608965
scalar Susp1=.1359734
scalar Susp0=.0978276
scalar MiscPro1=.1297074
scalar MiscPro0=.1079335
scalar Amend1=.3178144
scalar Amend0=.3066135 
scalar ProPart1=.208597
scalar ProPart0=.174206 
scalar MajTopic2_1=.0514301
scalar MajTopic2_0=.056308 
scalar MajTopic3_1=.0343752
scalar MajTopic3_0=.0506703
scalar MajTopic4_1=.0503019
scalar MajTopic4_0=.0362324
scalar MajTopic5_1=.0149977
scalar MajTopic5_0=.0299759
scalar MajTopic6_1=.0189794
scalar MajTopic6_0=.025507
scalar MajTopic7_1=.0657642
scalar MajTopic7_0=.0372637
scalar MajTopic8_1=.1053819
scalar MajTopic8_0=.1100034 
scalar MajTopic9_1=.0224965 
scalar MajTopic9_0=.023582
scalar MajTopic10_1=.0169885
scalar MajTopic10_0=.0220007
scalar MajTopic11_1=.0640388
scalar MajTopic11_0=.0775524
scalar MajTopic12_1=.0297963
scalar MajTopic12_0=.0329323 
scalar MajTopic13_1=.2243015 
scalar MajTopic13_0=.2219319
scalar MajTopic14_1=.0644369
scalar MajTopic14_0=.0694397
scalar MajTopic15_1=.0027872
scalar MajTopic15_0=.0045376
scalar MajTopic16_1=.049572
scalar MajTopic16_0=.0275696
scalar MajTopic17_1=.0248192 
scalar MajTopic17_0=.0349948
scalar MajTopic18_1=.0212356
scalar MajTopic18_0=.0365074
scalar MajTopic19_1=.0352379
scalar MajTopic19_0=.0255758
scalar MajTopic20_1=.0462539
scalar MajTopic20_0=.0295634
scalar MajTopic21_1=.0447939
scalar MajTopic21_0=.039395
scalar MajTopic22_1=.0118787
scalar MajTopic22_0=.0084565
scalar constant=1
generate x_betahatB_`i'=M1_b1*days + M1_b2*Post104_1 + M1_b3*daysPost104_1 + M1_b4*RegPass1 + M1_b5*Susp1 + M1_b6*MiscPro1 + M1_b7*Amend1 + M1_b8*ProPart1 + M1_b9*constant
generate predB_`i'=1/(1+exp(-(x_betahatB_`i')))
drop x_betahatB_`i'
}

foreach var of varlist predA_1-predA_735{
egen `var'a=clsort(`var')
}

foreach var of varlist predB_1-predB_735{
egen `var'b=clsort(`var')
}

save "Figure6c2_Values.dta"

drop M1_b1-predB_735
gen days=_n
*Keep the 8.25th and 91.75th percentiles
keep if days==825 | days==9175
xpose, clear
rename v1 LowBound
rename v2 UpBound
drop in 1471
gen days=_n
move days LowBound
gen Type="Early Cycle" if days<736
replace Type="Late Cycle" if days>735
replace days=days-735 if days>735

save "Figure6c2_Preds.dta"

*twoway (scatter LowBound days if Type=="Early Cycle") (scatter UpBound days if Type=="Early Cycle") (scatter LowBound days if Type=="Late Cycle") (scatter UpBound days if Type=="Late Cycle")
clear
*Reshape for figure
use "Figure6c2_Preds.dta"
sort days
gen shaper=1 if Type=="Early Cycle"
replace shaper=32 if Type=="Late Cycle"
drop Type
reshape wide LowBound UpBound, i(days) j(shaper)
save "Figure6c2_Preds_reshaped.dta"
clear



*****************************************
*Using Second Session Indicator
*****************************************

*****CYCLES*******

use "VoteTiming_MASTER.dta"

set more off 

set seed 1234

gen SecondSession=0
replace SecondSession=1 if VoteYear==1956 | VoteYear==1958 | VoteYear==1960 | VoteYear==1962 | VoteYear==1964 | VoteYear==1966 | VoteYear==1968 | VoteYear==1970 | VoteYear==1972 | VoteYear==1974 | VoteYear==1976 | VoteYear==1978 | VoteYear==1980 | VoteYear==1982 | VoteYear==1984 | VoteYear==1986 | VoteYear==1988 | VoteYear==1990 | VoteYear==1992 | VoteYear==1994 | VoteYear==1996 | VoteYear==1998 | VoteYear==2002 | VoteYear==2004 | VoteYear==2006 | VoteYear==2008 | VoteYear==2010 | VoteYear==2012 | VoteYear==2014 | VoteYear==2016 | VoteYear==2018 

gen SecondCycle=SecondSession*Cycle

gen DemPercYea=TotalDemYeas/TotalDemVotes
gen DemPercNay=TotalDemNays/TotalDemVotes
gen RepPercYea=TotalRepYeas/TotalRepVotes
gen RepPercNay=TotalRepNays/TotalRepVotes

gen HyperDivisive=0
replace HyperDivisive=1 if DemPercYea>=.9 & RepPercNay>=.9
replace HyperDivisive=1 if DemPercNay>=.9 & RepPercYea>=.9

logit HyperDivisive SecondSession Cycle SecondCycle RegPass Susp MiscPro Amend ProPart, robust

drawnorm M1_b1-M1_b9, n(10000) means(e(b)) cov(e(V)) clear

scalar SecondSess0=0
scalar SecondSess1=1
scalar Cycle1=8
scalar Cycle32=32
scalar Second0Cycle1=SecondSess0*Cycle1
scalar Second1Cycle1=SecondSess1*Cycle1
scalar Second0Cycle32=SecondSess0*Cycle32
scalar Second1Cycle32=SecondSess1*Cycle32
scalar RegPass1=.409396
scalar RegPass32=.0564103
scalar Susp1=.0939597
scalar Susp32=.0555556
scalar MiscPro1=.0469799
scalar MiscPro32=.7094017 
scalar Amend1=.114094 
scalar Amend32=.0632479 
scalar ProPart1=.261745
scalar ProPart32=.1068376
scalar MajTopic2_1=.033557 
scalar MajTopic2_32=.0216802
scalar MajTopic3_1=.0738255
scalar MajTopic3_32=.0135501 
scalar MajTopic4_1=0
scalar MajTopic4_32=.100271
scalar MajTopic5_1=.0268456
scalar MajTopic5_32=.0054201 
scalar MajTopic6_1=.0268456
scalar MajTopic6_32=0
scalar MajTopic7_1=.0268456
scalar MajTopic7_32=.1517615
scalar MajTopic8_1=.1543624
scalar MajTopic8_32=.0731707
scalar MajTopic9_1=0
scalar MajTopic9_32=.0216802
scalar MajTopic10_1=.0536913 
scalar MajTopic10_32=0
scalar MajTopic11_1=.0402685
scalar MajTopic11_32=.0406504
scalar MajTopic12_1=.033557
scalar MajTopic12_32=.0352304 
scalar MajTopic13_1=.2214765
scalar MajTopic13_32=.2195122
scalar MajTopic14_1=.0939597
scalar MajTopic14_32=.0677507
scalar MajTopic15_1=0
scalar MajTopic15_32=0
scalar MajTopic16_1=.0134228
scalar MajTopic16_32=.0596206
scalar MajTopic17_1=.0805369
scalar MajTopic17_32=.0108401
scalar MajTopic18_1=.0067114
scalar MajTopic18_32=.0542005 
scalar MajTopic19_1=.0469799
scalar MajTopic19_32=.0162602
scalar MajTopic20_1=.0201342
scalar MajTopic20_32=.0921409
scalar MajTopic21_1=.0469799
scalar MajTopic21_32=.0108401
scalar MajTopic22_1=0
scalar MajTopic22_32=.0054201
scalar constant=1
generate x_betahatA_0=M1_b1*SecondSess0 + M1_b2*Cycle1 + M1_b3*Second0Cycle1 + M1_b4*RegPass1 + M1_b5*Susp1 + M1_b6*MiscPro1 + M1_b7*Amend1 + M1_b8*ProPart1 + M1_b9*constant
generate predA_0=1/(1+exp(-(x_betahatA_0)))
drop x_betahatA_0

generate x_betahatA_1=M1_b1*SecondSess1 + M1_b2*Cycle1 + M1_b3*Second1Cycle1 + M1_b4*RegPass1 + M1_b5*Susp1 + M1_b6*MiscPro1 + M1_b7*Amend1 + M1_b8*ProPart1 + M1_b9*constant
generate predA_1=1/(1+exp(-(x_betahatA_1)))
drop x_betahatA_1

generate x_betahatB_0=M1_b1*SecondSess0 + M1_b2*Cycle32 + M1_b3*Second0Cycle32 + M1_b4*RegPass32 + M1_b5*Susp32 + M1_b6*MiscPro32 + M1_b7*Amend32 + M1_b8*ProPart32 + M1_b9*constant
generate predB_0=1/(1+exp(-(x_betahatB_0)))
drop x_betahatB_0

generate x_betahatB_1=M1_b1*SecondSess1 + M1_b2*Cycle32 + M1_b3*Second1Cycle32 + M1_b4*RegPass32 + M1_b5*Susp32 + M1_b6*MiscPro32 + M1_b7*Amend32 + M1_b8*ProPart32 + M1_b9*constant
generate predB_1=1/(1+exp(-(x_betahatB_1)))
drop x_betahatB_1

egen EarlyFirstSorted=clsort(predA_0)
egen EarlySecondSorted=clsort(predA_1)
egen LateFirstSorted=clsort(predB_0)
egen LateSecondSorted=clsort(predB_1)

drop M1_b1-predB_1

save "Figure6d1_Values.dta"

use "Figure6d1_Values.dta"

sum EarlyFirstSorted
scalar EFm=r(mean)
sum EarlySecondSorted
scalar ESm=r(mean)
sum LateFirstSorted
scalar LFm=r(mean)
sum LateSecondSorted
scalar LSm=r(mean)
gen days=_n
*Keep the 8.25th and 91.75th percentiles
keep if days==825 | days==9175 
drop days
xpose, clear
rename v1 LowBound
rename v2 UpBound
gen mean=.
replace mean=EFm in 1
replace mean=ESm in 2
replace mean=LFm in 3
replace mean=LSm in 4
gen Type="Early Cycle First Sess"
replace Type="Early Cycle Second Sess" in 2
replace Type="Late Cycle First Sess" in 3
replace Type="Late Cycle Second Sess" in 4
move mean UpBound
move Type LowBound

save "Figure6d1_Preds.dta"



*****POST-104 INDICATOR*******

use "VoteTiming_MASTER.dta"

set more off 

set seed 1234

gen post1994elec=1 if Cycle>=21
replace post1994elec=0 if post1994elec==.

gen SecondSession=0
replace SecondSession=1 if VoteYear==1956 | VoteYear==1958 | VoteYear==1960 | VoteYear==1962 | VoteYear==1964 | VoteYear==1966 | VoteYear==1968 | VoteYear==1970 | VoteYear==1972 | VoteYear==1974 | VoteYear==1976 | VoteYear==1978 | VoteYear==1980 | VoteYear==1982 | VoteYear==1984 | VoteYear==1986 | VoteYear==1988 | VoteYear==1990 | VoteYear==1992 | VoteYear==1994 | VoteYear==1996 | VoteYear==1998 | VoteYear==2002 | VoteYear==2004 | VoteYear==2006 | VoteYear==2008 | VoteYear==2010 | VoteYear==2012 | VoteYear==2014 | VoteYear==2016 | VoteYear==2018 

gen SecondPost=SecondSession*post1994elec

gen DemPercYea=TotalDemYeas/TotalDemVotes
gen DemPercNay=TotalDemNays/TotalDemVotes
gen RepPercYea=TotalRepYeas/TotalRepVotes
gen RepPercNay=TotalRepNays/TotalRepVotes

gen HyperDivisive=0
replace HyperDivisive=1 if DemPercYea>=.9 & RepPercNay>=.9
replace HyperDivisive=1 if DemPercNay>=.9 & RepPercYea>=.9

logit HyperDivisive SecondSession post1994elec SecondPost RegPass Susp MiscPro Amend ProPart, robust

drawnorm M1_b1-M1_b9, n(10000) means(e(b)) cov(e(V)) clear

scalar SecondSess0=0
scalar SecondSess1=1
scalar Post104_1=1
scalar Post104_0=.25
scalar Second0Post1=SecondSess0*Post104_1
scalar Second1Post1=SecondSess1*Post104_1
scalar Second0Post0=SecondSess0*Post104_0
scalar Second1Post0=SecondSess1*Post104_0
scalar RegPass1=.1130397
scalar RegPass0=.2608965
scalar Susp1=.1359734
scalar Susp0=.0978276
scalar MiscPro1=.1297074
scalar MiscPro0=.1079335
scalar Amend1=.3178144
scalar Amend0=.3066135 
scalar ProPart1=.208597
scalar ProPart0=.174206 
scalar MajTopic2_1=.0514301
scalar MajTopic2_0=.056308 
scalar MajTopic3_1=.0343752
scalar MajTopic3_0=.0506703
scalar MajTopic4_1=.0503019
scalar MajTopic4_0=.0362324
scalar MajTopic5_1=.0149977
scalar MajTopic5_0=.0299759
scalar MajTopic6_1=.0189794
scalar MajTopic6_0=.025507
scalar MajTopic7_1=.0657642
scalar MajTopic7_0=.0372637
scalar MajTopic8_1=.1053819
scalar MajTopic8_0=.1100034 
scalar MajTopic9_1=.0224965 
scalar MajTopic9_0=.023582
scalar MajTopic10_1=.0169885
scalar MajTopic10_0=.0220007
scalar MajTopic11_1=.0640388
scalar MajTopic11_0=.0775524
scalar MajTopic12_1=.0297963
scalar MajTopic12_0=.0329323 
scalar MajTopic13_1=.2243015 
scalar MajTopic13_0=.2219319
scalar MajTopic14_1=.0644369
scalar MajTopic14_0=.0694397
scalar MajTopic15_1=.0027872
scalar MajTopic15_0=.0045376
scalar MajTopic16_1=.049572
scalar MajTopic16_0=.0275696
scalar MajTopic17_1=.0248192 
scalar MajTopic17_0=.0349948
scalar MajTopic18_1=.0212356
scalar MajTopic18_0=.0365074
scalar MajTopic19_1=.0352379
scalar MajTopic19_0=.0255758
scalar MajTopic20_1=.0462539
scalar MajTopic20_0=.0295634
scalar MajTopic21_1=.0447939
scalar MajTopic21_0=.039395
scalar MajTopic22_1=.0118787
scalar MajTopic22_0=.0084565
scalar constant=1

generate x_betahatA_0=M1_b1*SecondSess0 + M1_b2*Post104_0 + M1_b3*Second0Post0 + M1_b4*RegPass0 + M1_b5*Susp0 + M1_b6*MiscPro0 + M1_b7*Amend0 + M1_b8*ProPart0 + M1_b9*constant
generate predA_0=1/(1+exp(-(x_betahatA_0)))
drop x_betahatA_0

generate x_betahatA_1=M1_b1*SecondSess1 + M1_b2*Post104_0 + M1_b3*Second1Post0 + M1_b4*RegPass0 + M1_b5*Susp0 + M1_b6*MiscPro0 + M1_b7*Amend0 + M1_b8*ProPart0 + M1_b9*constant
generate predA_1=1/(1+exp(-(x_betahatA_1)))
drop x_betahatA_1

generate x_betahatB_0=M1_b1*SecondSess0 + M1_b2*Post104_1 + M1_b3*Second0Post1 + M1_b4*RegPass1 + M1_b5*Susp1 + M1_b6*MiscPro1 + M1_b7*Amend1 + M1_b8*ProPart1 + M1_b9*constant
generate predB_0=1/(1+exp(-(x_betahatB_0)))
drop x_betahatB_0

generate x_betahatB_1=M1_b1*SecondSess1 + M1_b2*Post104_1 + M1_b3*Second1Post1 + M1_b4*RegPass1 + M1_b5*Susp1 + M1_b6*MiscPro1 + M1_b7*Amend1 + M1_b8*ProPart1 + M1_b9*constant
generate predB_1=1/(1+exp(-(x_betahatB_1)))
drop x_betahatB_1

egen EarlyFirstSorted=clsort(predA_0)
egen EarlySecondSorted=clsort(predA_1)
egen LateFirstSorted=clsort(predB_0)
egen LateSecondSorted=clsort(predB_1)

drop M1_b1-predB_1

save "Figure6d2_Values.dta"

use "Figure6d2_Values.dta"

sum EarlyFirstSorted
scalar EFm=r(mean)
sum EarlySecondSorted
scalar ESm=r(mean)
sum LateFirstSorted
scalar LFm=r(mean)
sum LateSecondSorted
scalar LSm=r(mean)
gen days=_n
*Keep the 8.25th and 91.75th percentiles
keep if days==825 | days==9175 
drop days
xpose, clear
rename v1 LowBound
rename v2 UpBound
gen mean=.
replace mean=EFm in 1
replace mean=ESm in 2
replace mean=LFm in 3
replace mean=LSm in 4
gen Type="Early Cycle First Sess"
replace Type="Early Cycle Second Sess" in 2
replace Type="Late Cycle First Sess" in 3
replace Type="Late Cycle Second Sess" in 4
move mean UpBound
move Type LowBound

save "Figure6d2_Preds.dta"



